package day7;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author oldliu
 * @since 1.0
 */
public class CreatSTu {
    public static void main(String[] args) {
        Class<Student> c1 = Student.class;
//        Student student = c1.newInstance();//无参构造
//        System.out.println(student);
        try {
            Constructor<Student> c2 = c1.getDeclaredConstructor(String.class, String.class);
            c2.setAccessible(true);//突破private限制
            Student student = c2.newInstance("吴浩林", "六安");
            System.out.println(student);
            //设置属性
            Field fphone=c1.getDeclaredField("phone");
            fphone.setAccessible(true);
            fphone.set(student,"139587744444");

            System.out.println(student);
            Object p = fphone.get(student);
            System.out.println(p+">>>"+p.getClass());
            Method mage = c1.getDeclaredMethod("incAge", int.class);
            Object invoke = mage.invoke(student, 15);
            System.out.println(invoke+" 返回了。。。");
            System.out.println(student);
        } catch ( Exception e) {
            e.printStackTrace();
        }

    }
}
